//
//  CZVisitorTableViewController.swift
//  Blog
//
//  Created by whitcast on 16/7/9.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZVisitorTableViewController: UITableViewController {
    
    // 登录标识
    var isLogin: Bool = CZUserAccountViewModel.shareUserAccount.islogin
    
    // 访客视图
    var visitorView: CZVisitorView?
    
    override func loadView() {
        if isLogin {
            super.loadView()
        } else {
            //未登录需要访客视图
            visitorView = CZVisitorView()
            // 使用[weak self]解决循环闭包
            visitorView?.loginClosure = {
                [weak self] in self?.showOAuthLogin()
            }
            view = visitorView
            setupNavUI()
        }
   
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
       
    }
    
    private func setupNavUI() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "registerAction")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginAction")
    }
    
    @objc private func registerAction() {
        print("注册按钮点击了")
        showOAuthLogin()
    }
    
    @objc private func loginAction() {
        print("登录按钮点击了")
        showOAuthLogin()
    }
    // OAuth登录页面
    private func showOAuthLogin() {
        let oAuthVC = CZOAuthViewController()
        let nav = UINavigationController(rootViewController: oAuthVC)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
}
